package com.etao.tools.service;

import com.etao.tools.Iservice.IStatisticsService;
import com.etao.tools.common.ExportExcel;
import com.etao.tools.common.PropertyUtils;
import com.etao.tools.common.email.EmailUtil;
import com.etao.tools.dao.StatisticsDao;
import com.etao.tools.entity.userDishInfoEntity;
import com.etao.tools.entity.userInfoEntity;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by lyp on 2016/8/8.
 */
@Service
public class StatisticsService implements IStatisticsService {
   protected static final org.slf4j.Logger log = LoggerFactory.getLogger("com.etao.tools.dao.StatisticsDao.StatisticsService");
@Autowired
private StatisticsDao statisticsDao;

    //每日新用户报表
    public List<userInfoEntity> newUserlistByDay()
    {
        List<userInfoEntity> result= statisticsDao.newUserlistByDay();
        return result;
    }

    public List<userInfoEntity> userListByDay()
    {
        List<userInfoEntity> result= statisticsDao.userListByDay();
        return result;
    }

    public List<userInfoEntity> reUserListBy7Days()
    {
        List<userInfoEntity> result= statisticsDao.reUserListBy7Days();
        return result;
    }

    public List<userDishInfoEntity> costListByDay()
    {
        List<userDishInfoEntity> result= statisticsDao.costListByDay();
        return result;
    }

    public void statisticsAndSendEmail() {
        String dateNow = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); //当前日期

        ExportExcel excel = ExportExcel.getInstance();
        List<userInfoEntity> getNewUserlist = statisticsDao.newUserlistByDay();
        List<userInfoEntity> getUserList = statisticsDao.userListByDay();
        List<userInfoEntity> getReUserList = statisticsDao.reUserListBy7Days();
        List<userDishInfoEntity> getCostList = statisticsDao.costListByDay();

        excel.AddNewUserlistSheet(getNewUserlist);
        excel.AddUserListSheet(getUserList);
        excel.AddReUserListSheet(getReUserList);
        excel.AddCostListSheet(getCostList);

        ExportExcel.Export("4个报表（"+dateNow+"）.xls");
        EmailUtil.sendEmail("每日统计数据","Hello All: 请查收附件~",
                PropertyUtils.getProperty("ecb.mail.to").split(";"), "4个报表（"+dateNow+"）.xls");
    }
}
